<?php
 if(!isset($sp))	
  	$sp=explode("/",$_SERVER['PHP_SELF']);

  if($_SERVER['HTTP_HOST'] == "localhost" || $_SERVER['HTTP_HOST'] == "192.168.1.34")
   {
	  $sp[1] = '/' . $sp[1];
   }
  else
	  $sp[1] = '';
  
  $w_root = $_SERVER['SERVER_NAME'] . $sp[1];
  $w_root = str_replace('//','/',$w_root);
  $w_root = str_replace('\\\\','\\',$w_root);
  
  $s_root = $_SERVER['DOCUMENT_ROOT'] . $sp[1];
  $s_root = str_replace('//','/',$s_root);
  $s_root = str_replace('\\\\','\\',$s_root); 
/*========End Setting up web root and server root =============*/
  require_once $s_root.'/libraryfiles/config.php'; 

//if not login 
if(empty($_SESSION['username']))
{
    ?>
    <script type="text/javascript">
        window.location = "<?php echo W_ROOT;?>/login.php?return_url=<?php echo $CURRENT_URL;?>"
    </script>
    <?php
    exit();
}
// end if not login
$include = '
<script type="text/javascript" src="'.W_ROOT.'/js/common.js"></script>
<script type="text/javascript" src="'.W_ROOT.'/js/jquery.js"></script>
';	
$view = isset($_GET['view']) ? $_GET['view'] : '';
switch ($view) {
    //this is case for add promotion
    case'add_promotion':
        if (isset($_GET['id'])) {
            $id = (int) $_GET['id'];
        } else if (isset($_POST['id'])) {
            $id = $_POST['id'][0];
        }
        else
            $id = 0;

        $site_title = "Seller Site - Add New Promotion";
        $content = 'add_promotion.php';
        break;
    //this is case for delete promotion
    case 'delete_promotion':
        if (isset($_GET['view']) && $_GET['view'] == 'delete_promotion') {
            $id = $_GET['id'];
            $sql = "DELETE FROM promotion WHERE promotion_id=$id";
            mysql_query($sql);
            
            header('Location: index.php');
        }
        break;
    //this is case for edit promotion
    case'edit_promotion':
        if (isset($_GET['id'])) {
            $id = (int) $_GET['id'];
        } else if (isset($_POST['id'])) {
            $id = $_POST['id'][0];
        }
        else
            $id = 0;

        $site_title = "Seller Site - Edit Promotion";
        $content = 'edit_promotion.php';
        break;        
    default:
        $content = 'promotion.php';
        break;
}

require_once TMP_SELL_ADMIN_PATH;
?>